[ruby] Check if file is a valid image

Posted by some guy on Stack Overflow See other posts from Stack Overflow or by some guy
Published on 2010-05-07T19:06:50Z Indexed on 2010/05/07 20:28 UTC
Read the original article Hit count: 200

Filed under:

Hi all,

I'm using rmagick to manipulate image files. I use the ImageList.new on each file to get started. When I apply this method to an invalid image file I get the below error which interrupts the execution of the script:

RMagick.rb:1635:in `read': Improper image header (Magick::ImageMagickError)

Therefore I would like to be able to check whether a file is a valid image file before using this method.

Any ideas? Thanks.

© Stack Overflow or respective owner

Related posts about ruby